package com.central.apps.handler.contract;

import com.central.app.common.quartz.QuartzJob;
import com.central.app.service.HandlerService;
import com.central.bizcommon.model.schedule.JobParams;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Administrator on 2022/9/21.
 */
@Component
@Slf4j
@DisallowConcurrentExecution
public class NodeCheckTask extends QuartzJob {

    @Autowired
    private HandlerService handlerService;
    @Override
    protected void executeJob(JobExecutionContext jobExecutionContext, String s, String s1, List<JobParams> list) throws JobExecutionException {

        //查询所有的合同节点集合数据，检查开始时间，开始时间大于当前时间时，合同节点状态自动改为进行中

        String sql = "update gq_connodenew set status = '进行中' where status='未开始' and starttime <NOW()";
        handlerService.updateBySql(sql);
        //合同开始时间到了--已生效
        String sql2 ="update gq_conaccount set constatus = '已生效' where constatus = '已签订' and starttime <NOW()";
        handlerService.updateBySql(sql2);
        String sql5 ="update gq_coninfo set constatus = '已生效' where concode in (select concode from gq_conaccount where constatus = '已签订' and starttime <NOW())";
        handlerService.updateBySql(sql5);
        //合同第一个节点到了，--执行中
        String sql3 = "update gq_conaccount set constatus = '执行中' where concode in( select concode from gq_connodenew where starttime <NOW() and status='未开始') and constatus ='已生效'";
        handlerService.updateBySql(sql3);
        String sql4 = "update gq_coninfo set constatus ='执行中' where concode in( select concode from gq_connodenew where starttime <NOW() and status='未开始') and constatus ='已生效'";
        handlerService.updateBySql(sql4);
//        //合同签订公示期到了之后，更改合同流程状态
//        String sql6 = "update gq_consigns set status = '已公示' where publicityend <NOW()";
//        handlerService.updateBySql(sql6);

        //合同申请，公示期到了之后，修改合同申请的状态
        handlerService.updateBySql("update gq_conapplication set constatus = '待评审',status='已公示' where publicityend <NOW() and isreview = '是'");
        handlerService.updateBySql("update gq_conapplication set constatus = '待签订',status='已公示' where publicityend <NOW() and isreview = '否'");
        //公示期到了进行删除
        handlerService.updateBySql("update gq_notice set status = '公示完毕',isshow=0  where endtime < NOW() ");

    }
}
